from time import sleep

from common.readaccountinfo import ReadConfig
from page.mainpage import MainPage


class CompositionManagement(MainPage):


    def goto_compositionmanagement(self):
        """
        进入侧导航栏排序第一的县级的学校管理
        打开第一所学校管理菜单
        进入优秀作文
        :return:
        """
        self.click("css", '#app > div > section > div > div:nth-child(2) > section > ul > li:nth-child(1)')
        self.click("css",
                   '#app > div > section > div > div:nth-child(2) > section > ul > li.secondstage.el-submenu.is-active.is-opened > ul > li:nth-child(1)')
        self.click("xp", "//*[text()='优秀作文']")
        sleep(1)

    def loacate_addcomposition(self):
        """
        定位发布作文按钮
        :return:
        """
        self.locate("css","div.options > div.actionsgroup > button:nth-child(3)")

    def add_composition(self,title,author,content):
        """
        点击发布作文
        打开下拉框
        选择接收班级
        关闭下拉框
        输入标题
        输入作者
        输入内容
        点击提交
        :return:
        """
        self.click("css","div.options > div.actionsgroup > button:nth-child(3)")
        self.click("css","#app > div > section > div > div:nth-child(2) > div > div.main-content > section > section > section > section > div:nth-child(1) > div > div > span > div > i")
        self.click("xp","//*[text()='初一']")
        self.click("css",
                   "#app > div > section > div > div:nth-child(2) > div > div.main-content > section > section > section > section > div:nth-child(1) > div > div > span > div > i")
        self.send_keys("css","#app > div > section > div > div:nth-child(2) > div > div.main-content > section > section > section > section > div:nth-child(2) > div > div > input",title)
        self.send_keys("css","#app > div > section > div > div:nth-child(2) > div > div.main-content > section > section > section > section > div:nth-child(3) > div > div > input",author)
        self.send_keys("cn","w-e-text",content)
        self.click_submit()

if __name__ == '__main__':
    # 打开谷歌浏览器,输入测试地址
    login = CompositionManagement(ReadConfig().get_http('browsertype'), ReadConfig().get_http('url'))
    # 输入登录账号,密码
    login.login(ReadConfig().get_account('username'), ReadConfig().get_account('password'))
    # 进入电子班牌系统
    login.goto_electroniclassbrand()
    # 进入云控中心(县级管理)
    login.goto_cloudcontrolcenter()
    login.goto_compositionmanagement()
    login.add_composition("出师表","诸葛亮","先帝创业未半而中道崩殂")